import { createOperationsGenerator } from '#image'
import type { ProviderGetImage } from '@nuxt/image'

const operationsGenerator = createOperationsGenerator()

export const getImage: ProviderGetImage = (src, { modifiers = {}, baseURL } = {}) => {
  const operations = operationsGenerator(modifiers)
  const { width, height, compress } = modifiers
  const whopStr = width || height ? `${width ? `/w/${width}` : ''}${height ? `/h/${height}` : ''}` : ''
  const compressStr = compress ? `/q/50` : ''
  return {
    url: src + `?imageView2/0${whopStr}/format/webp${compressStr}/ignore-error/1`,
  }
}
